/*
 * @Author: Oscar Pena
 * CS431 2011
 * Simulates the code written by the users over a course. 
 * Few predefined courses are available for simulation. 
 * User also can generate its own courses with the help of the Terrain Editor Module.
 * */
package FlowGram.Application.SimulatorWindow.Simulator;

import javax.swing.JSplitPane;

import FlowGram.Application.Application;
import FlowGram.Application.Parser.FinchProgramFlow;
import FlowGram.Application.Parser.Controllers.FinchConsoleController;
import FlowGram.Application.SimulatorWindow.SimulationWindow;
import FlowGram.Application.SimulatorWindow.TerrainEditor.Finch;
import FlowGram.Application.SimulatorWindow.TerrainEditor.Terrain;
import FlowGram.Application.SimulatorWindow.TerrainEditor.TerrainImage;

public class SimulatorEngine {
	SimulationController simcon;

	
	public SimulatorEngine() {
		simcon = new SimulationController();
	}
	public void setTerrain(Terrain map, JSplitPane splitPaneV, TerrainImage terrainImage ){
		simcon.setTerrain(map, splitPaneV, terrainImage);
	}

	public void runsimulation(FinchProgramFlow flow){
		simcon.setStep(false);
		if (!flow.hasController(simcon.getName())){
			flow.addController(simcon);

		}
		
		if (Application.getInstance().isFinchConnected()==true){
			if (!flow.hasController(Application.getInstance().getFinchController().getName())){
				flow.addController(Application.getInstance().getFinchController());
			}
		}
		flow.execute();	
	}
	public void runsimulationstep(FinchProgramFlow flow) {
		simcon.setStep(true);
		System.out.println("runsimulationstep()");
		if (!flow.hasController(simcon.getName())){
			flow.addController(simcon);
		}
		flow.execute();	
		
	}
	public void setFinch(Finch finch) {
		// TODO Auto-generated method stub
		simcon.setFinch(finch);
	}
	public void setMessageBox(MessageBox messages) {
		// TODO Auto-generated method stub
		simcon.setMessageBox(messages);
		
	}
	


}
